package com.guide.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.guide.dao.PersonalDao;
import com.guide.domain.Personal;
import com.guide.domain.PersonalQuery;
import com.guide.domain.Travelorg;
import com.guide.domain.TravelorgQuery;
import com.guide.persistence.PersonalMapper;
@Repository("personalDao")
public class PersonalDaoImpl implements PersonalDao{

	@Autowired
	private PersonalMapper personalMapper;
	@Override
	public long insertPersonal(Personal personal) {
		// TODO Auto-generated method stub
		return personalMapper.insert(personal);
	}

	@Override
	public Personal getPersonalByUserId(Long userId) {
		PersonalQuery query = new PersonalQuery();
		query.createCriteria().andUserIdEqualTo(userId);
		List<Personal> personals = personalMapper.selectByExampleWithBLOBs(query);
		if(!CollectionUtils.isEmpty(personals)){
			return personals.get(0);
		}
		return null;
	}

	@Override
	public void updateByPrimaryKeySelective(Personal personal) {
		// TODO Auto-generated method stub
		personalMapper.updateByPrimaryKeySelective(personal);
	}

	@Override
	public Personal getPersonalById(Long id) {
		// TODO Auto-generated method stub
		return personalMapper.selectByPrimaryKey(id);
	}

	@Override
	public Personal getPersonalByIdnum(String idnum) {
		// TODO Auto-generated method stub
		PersonalQuery query = new PersonalQuery();
		query.createCriteria().andIdnumEqualTo(idnum);
		List<Personal> personalList = personalMapper.selectByExample(query);
		if(!CollectionUtils.isEmpty(personalList)) {
			return personalList.get(0);
		}
		return null;
	}

}
